package com.jindianjichi.auth.domain.service.impl;

import com.jindianjichi.auth.common.enums.IsDeletedEnum;
import com.jindianjichi.auth.domain.BO.AuthRolePermissionBO;
import com.jindianjichi.auth.domain.service.AuthRolePermissionDomainService;
import com.jindianjichi.auth.infra.basic.entity.AuthRolePermission;
import com.jindianjichi.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Autowired
    private AuthRolePermissionService authRolePermissionService;
    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission>list=new LinkedList<>();
        for (Long permisionId : authRolePermissionBO.getPermissionIdList()) {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(authRolePermissionBO.getRoleId());
            authRolePermission.setPermissionId(permisionId);
            authRolePermission.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
        }
        //批量增加用户权限
        int count=authRolePermissionService.insertBatch(list);
        return count==list.size();
    }
}
